<?php 

class Araclar{
	
	public static function anaKategoriDiziGetir(){
		return array(
					'1' => Araclar::yaz('ÖZ BAKIM BECERİLERİ','SELF CARE SKILLS'),
					'2' => Araclar::yaz('EV İÇİ BECERİLERİ','DOMESTIC SKILLS'),	
		);
	}	
	
	public static function ipucuDiziGetir(){
		return array(
					'0' => '',
					'1' => '+',	
					'2' => 'F',	
					'3' => 'M',	
					'4' => 'S',	
		);
	}	

	public static function yeniDizi($dizi){
		$yeni_dizi = array();	
		$yeni_dizi["0"]=" ";
		foreach ($dizi as $key => $value) {
    		$yeni_dizi["$key"]=$value;
		}
		return $yeni_dizi;
	}
	
	public static function tarihToStr($tarih,$saatGoster=false){
		if($tarih>0){
			if($saatGoster){
				return date('d.m.Y H:i',$tarih);
			}else{
				return date('d.m.Y',$tarih);
			}
		}else{
			return "";
		}
	}
	
	public static function strToTarih($str){
		return CDateTimeParser::parse($str,'dd.MM.yyyy') ? CDateTimeParser::parse($str,'dd.MM.yyyy') : 0;
	}

	public static function strToTarihSaat($str){
		$zaman_int = DateTime::createFromFormat("d.m.Y - G:i", $str);
		return $zaman_int->getTimestamp();
	}
	
	public static function tarihSaatToStr($zaman){
		$yeniDateTime = new DateTime();
		$yeniDateTime->setTimestamp($zaman);
		return $yeniDateTime->format("d.m.Y - G:i");
	}
	
	public static function trace($var){
		echo Yii::trace(CVarDumper::dumpAsString($var),'vardump');
	}
	
	public static function dosyaAdiOlustur($str){
		$str = str_replace("İ","I",$str);
		$str = str_replace("ı","i",$str);
		$str = str_replace("Ö","O",$str);
		$str = str_replace("ö","o",$str);
		$str = str_replace("Ü","U",$str);
		$str = str_replace("ü","u",$str);
		$str = str_replace("Ç","C",$str);
		$str = str_replace("ç","c",$str);
		$str = str_replace("Ğ","G",$str);
		$str = str_replace("ğ","g",$str);
		$str = str_replace("Ş","S",$str);
		$str = str_replace("ş","s",$str);
		$str = str_replace(" ","_",$str);
		return $str;	
	}
	
	public static function trToEn($text) {
		$text = trim($text);
		$search = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü');
		$replace = array('c','c','g','g','i','i','o','o','s','s','u','u');
		$new_text = str_replace($search,$replace,$text);
		return $new_text;
	} 

	public static function kullaniciAdiGetir($id){
		$m = Kullanicilar::model()->findByPk($id);
		return $m->ad." ".$m->soyad;
	}	
	
	public static function yaz($tr,$en=''){
		if(Yii::app()->getLanguage()=='tr' || empty($en))
		{
			return $tr;
		}else{
			return $en;
		}
	}
	
	public static function dosyaDilUzanti(){
		if(Yii::app()->getLanguage()=='tr')
		{
			return "";
		}else{
			return "_en";
		}
	}
	
	public static function logla()
	{
		 if(!Yii::app()->user->isGuest){
			$log = new Log();
			$log->tarih = time();
			$log->kullanici_id = Yii::app()->user->getId();
			$log->controller = Yii::app()->controller->id;
			$log->action = Yii::app()->controller->action->id;
			$log->get = Araclar::arrayToString($_GET);
			$log->post = Araclar::arrayToString($_POST);
			$log->aciklama = "";
			$log->save();
		 }
	}
	
	public static function arrayToString($dizi)
	{
		if(!is_array($dizi)) return "";
		$metin="";
		foreach($dizi as $key => $value)
		{
			if(is_array($value)){
				$metin .= Araclar::arrayToString($value)."|";
			}else{
				$metin .= $key.":".$value."|";
			}
		}
		return substr($metin, 0, strlen($metin)-1);
	}

	public static function mailGonder($email,$message,$subject='BYE'){
		MailRobot::mailGonder($email, $message, $subject);
	}	
	
	public static function smsGonder($cep_tel,$mesaj){
		$user = "serkancankaya";
		$password = "Camasir198579";
		$api_id = "3385382";
		$baseurl ="http://api.clickatell.com";
		$m = urlencode(Araclar::trToEn($mesaj));
		$url="http://api.clickatell.com/http/sendmsg?user=$user&password=$password&api_id=$api_id&to=$cep_tel&text=$m";
		$ret = file($url);
		//Araclar::trace($ret);
	} 
	
	public static function linkKoy($url,$icerik,$class='button normal',$uyari=true){
		if($uyari){
			$html = "<div onClick='guvenliGecis(\"$url\")' class='$class'>$icerik</div>";	
		}else{
			$html = "<div onClick='document.location=\"$url\";' class='$class'>$icerik</div>";	
		}
		return $html;
	}
	
	public static function sayfaAltiButonlari($geri,$yukari,$ileri,$diger=array()){
		$genislik=150;
		$html = "<div align='right'>";
		$html .=	"<table border=0>";
		$html .=	"<tr>";
		for($i=0;$i<count($diger);$i++){
			$html .= "<td width='$genislik' align='center'>".$diger[$i]."</td>";
		}
		if($geri!=""){
			$html .= "<td width='$genislik' align='center'>";
			$html .= Araclar::linkKoy(Yii::app()->createUrl($geri), "<img src='/images/geri.gif' border=0 width='18px'/> ".Araclar::yaz("Önceki","Prev"));
			$html .= "</td>";
		}else{
			$html .= "<td width='$genislik' align='center'>&nbsp;</td>";
		}
		if($yukari!=""){
			$html .= "<td width='$genislik' align='center'>";
			$html .= Araclar::linkKoy(Yii::app()->createUrl($yukari),"<img src='/images/yukari.gif' border=0 width='18px'/> ".Araclar::yaz("Üst Menü","Up")); 
			$html .= "</td>";
		}else{
			$html .= "<td width='$genislik' align='center'>&nbsp;</td>";
		}
		if($ileri!=""){
			$html .= "<td width='$genislik' align='center'>";
			$html .= Araclar::linkKoy(Yii::app()->createUrl($ileri),"<img src='/images/ileri.gif' border=0 width='18px'/> ".Araclar::yaz("Sonraki","Next"));
			$html .= "</td>";
		}else{
			$html .= "<td width='$genislik' align='center'>&nbsp;</td>";
		}
		$html .= "</tr>";
		$html .= "</table>";
		$html .= "</div>";
		return $html;
	}
}
?>